function tildec = findtildec(Xit,Cg,Y,MU,Nstates,T)
%findtildeP is a function that helps us find the guarantted price given
%history.
%tildeP=min[P_1(lambda_1),P_2(lambda_2),..., P_t(Lambda_t)]
th=length(Xit);
%first we find guaranteed price tildeP
Y1 = repmat(reshape(Y,1,1,T),Nstates+1,1);
C=Y1-MU;
C(Nstates+1,:,:)=0;
tildec=min(C, [], 'all');
for i=1:(th)
    if Xit(i)==Nstates+1
        tildec=0;
        break
    end
    if tildec<Cg(Xit(i),i)
        tildec=Cg(Xit(i),i);
    end
end
end